Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[perf]: optimize optimizer #3782

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Feb 14, 2024

What I did

improve compilation-time by 10-15%, but it's a little gross

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

def optimized(self):
if self._optimized is None:
# TODO figure out how to fix this circular import
from vyper.ir.optimizer import optimize

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.ir.optimizer
begins an import cycle.
@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 85.03%. Comparing base (a0d9b1f) to head (c597129).

Current head c597129 differs from pull request most recent head 7fcd302

Please upload reports for the commit 7fcd302 to get more accurate results.

Files Patch % Lines
vyper/codegen/ir_node.py 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3782      +/-   ##
==========================================
- Coverage   91.08%   85.03%   -6.06%     
==========================================
  Files         106       92      -14     
  Lines       15315    13722    -1593     
  Branches     3368     3081     -287     
==========================================
- Hits        13950    11668    -2282     
- Misses        928     1566     +638     
- Partials      437      488      +51     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@charles-cooper
Copy link
Member Author

i checked whether caching _optimized is safe, and i think it is. the concern is that IRnodes are mutable (and the metadata on them is sometimes mutated, but those aren't used in optimization). there aren't really any places where IRnode args are written to - they are in rewrite_return_sequences as part of assembly emission, but that happens after optimization. the only other places where they are in the constructor and in deepcopy.

(vyper) ~/vyper $ git grep "\.args\[.* = "
vyper/ir/compile_ir.py:            ir_node.args[0].value = "pass"
vyper/ir/compile_ir.py:            ir_node.args[1].value = "pass"
vyper/ir/compile_ir.py:        withargs[code.args[0].value] = height
vyper/ir/compile_ir.py:            withargs[code.args[0].value] = old

(vyper) ~/vyper $ git grep "\.args ="
tests/functional/codegen/features/test_logging_from_call.py:    assert logs[0].args == logs[1].args
tests/functional/codegen/features/test_logging_from_call.py:    assert logs[0].args == logs[1].args
vyper/ast/parse.py:        fn_node.args = python_ast.arguments(defaults=[])
vyper/codegen/ir_node.py:        self.args = args
vyper/codegen/ir_node.py:        ret.args = [copy.deepcopy(arg) for arg in ret.args]
vyper/codegen/ir_node.py:            and self.args == other.args
vyper/ir/compile_ir.py:            ir_node.args = IRnode.from_list(_t, source_pos=ir_node.source_pos).args
vyper/ir/optimizer.py:        return x.args == y.args == [] and x.value == y.value and not x.is_complex_ir
vyper/venom/function.py:        self.args = []

i guess dunder things don't get into the __dict__ object?
Copy link
Collaborator

@harkal harkal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like explicit caching where you can see easily that things get cached and clearly when caches are/need to be invalidated. @cachedproperty scares me :)

@charles-cooper
Copy link
Member Author

closing this, we are planning to axe the old IR pipeline anyway so we don't really need to focus on improvements to it.

@charles-cooper charles-cooper reopened this May 2, 2024
@charles-cooper charles-cooper changed the title optimize optimizer feat[perf]: optimize optimizer May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants